/**
 * 
 */
package de.homer.server.service.rest;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import de.homeR.services.HomeRConfigurationService;
import de.homeR.services.domain.PluginMetaInformationCollection;
import de.homer.adapter.domain.ConfiguredPlugin;
import de.homer.persistence.adapter.ConfiguredPluginRepository;
import de.homer.persistence.adapter.PluginRepository;

/**
 * @author André Stannek
 * 
 */
@Controller
@RequestMapping("/config")
public class HomeRConfigurationServiceREST implements HomeRConfigurationService {

	/**
	 * 
	 */
	@Autowired
	private ConfiguredPluginRepository configuredPluginRepository;

	/**
	 * 
	 */
	@Autowired
	private PluginRepository pluginRepository;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * de.homeR.services.HomeRConfigurationService#getAllConfiguredPlugins()
	 */
	@RequestMapping(value = "/configuredplugins", method = RequestMethod.GET)
	@ResponseBody
	@Override
	public final List<ConfiguredPlugin> getAllConfiguredPlugins() {
		return new ArrayList<>(configuredPluginRepository.getAll());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.homeR.services.HomeRConfigurationService#getAllPlugins()
	 */
	@RequestMapping(value = "/plugins", method = RequestMethod.GET)
	@ResponseBody
	@Override
	public final PluginMetaInformationCollection getAllPlugins() {
		return new PluginMetaInformationCollection(pluginRepository.getAll());
	}
}
